package com.cmower.dzone.compareArrayAndCheckMismatches;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 沉默王二，一枚有趣的程序员
 */
public class EqualWriterDemo {
    public static void main(String[] args) {
Writer [] writer1 = {new Writer(18,"沉默王二"),new Writer(16,"沉默王三")};
Writer [] writer2 = {new Writer(18,"沉默王二"),new Writer(16,"沉默王三")};
Writer [] writer3 = {new Writer(18,"沉默王一"),new Writer(16,"沉默王三")};

System.out.println(Arrays.equals(writer1,writer2));
System.out.println(Arrays.equals(writer1,writer3));

System.out.println(Arrays.mismatch(writer1,writer2));
System.out.println(Arrays.mismatch(writer1,writer3));


Comparator<Writer> byAge = Comparator.comparing(Writer::getAge);
Comparator<Writer> byName = Comparator.comparing(Writer::getName);

System.out.println(Arrays.equals(writer1, writer3, byAge));
System.out.println(Arrays.equals(writer1, writer3, byName));


System.out.println(Arrays.mismatch(writer1, writer3, byAge));
System.out.println(Arrays.mismatch(writer1, writer3, byName));
    }
}
